$(function () {
    $(function () {
        var options = {
            modalName: "用户",
            url: "/render/userManager/list",
            getInfoUrl: "/render/userManager/get/{id}",
            updateUrl: "/render/userManager/edit",
            removeUrl: "/render/userManager/remove",
            createUrl: "/render/userManager/add",
            searchUrl: "/render/userManager/search",
            pageNumber:1,
            pageSize:7,
            columns: [
                {
                    checkbox: true,
                    formatter:checkboxMatter
                }, {
                    field: 'id',
                    title: 'ID',
                    align: "center",
                    width: '50px',
                    class:"colStyle",
                    sortable : true,
                    formatter:paramsMatter
                }, {
                    field: 'username',
                    title: '名字',
                    align: "center",
                    width: '100px',
                    class:"colStyle",
                    formatter:paramsMatter
                }, {
                    field: 'password',
                    title: '密码',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    formatter:paramsMatter
                }, {
                    field: 'email',
                    title: '邮箱',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    formatter:paramsMatter
                }, {
                    field: 'shop_id',
                    title: '店铺id',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    formatter:paramsMatter
                }, {
                    field: 'role',
                    title: '角色',
                    align: "center",
                    width: '88px',
                    class:"colStyle",
                    // formatter:paramsMatter
                    formatter: function (value) {

                        if (value == 1) {
                            value='管理员';
                        }

                        if (value == 2) {
                            value='店长';
                        }

                        if (value == 3) {
                            value='店员';
                        }

                        if (value == 4) {
                            value='普通用户';
                        }

                        // value = (value==1) ? '上架' : '下架';
                        var span=document.createElement('span');
                        span.setAttribute('title',value);
                        span.innerHTML = value;
                        return span.outerHTML;
                    }
                }, {
                    field: 'createTime',
                    title: '创建时间',
                    width: '88px',
                    align: "center",
                    sortable : true,
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }, {
                    field: 'updateTime',
                    title: '更新时间',
                    width: '88px',
                    align: "center",
                    sortable : true,
                    cellStyle:formatTableUnit,
                    formatter:paramsMatter
                }, {
                    field: 'operate',
                    title: '操作',
                    align: "center",
                    width: '100px',
                    formatter: operateFormatter //自定义方法，添加操作按钮
                }
            ]
        };
        // 初始化table组件
        var table = new Table(options);
        table.init();
        //search按钮绑定查询事件
        $('#btnSearch').on('click', function () {
            var searchText = {
                username: $("#search-username").val(),
                searchid: $("#search-id").val(),
                email: $("#search-email").val()==null?'':$("#search-email").val(),
                shopid: $("#search-shop_id").val()==null?'':$("#search-shop_id").val()
            };

            // console.log("searchText="+searchText);
            if($("#search-username").val() === ""&&$("#search-id").val() === ""&&$("#search-email").val() === ""&&$("#search-shop_id").val() === ""){
                postParams(options.url,options.onExpandRow,options,options.rowStyle,options.columns,null,true);
            }else {
                postParams(options.searchUrl,options.onExpandRow,options,options.rowStyle,options.columns,JSON.stringify(searchText),false);
            }
        });
    });

    $(".close,.btn-default").on("click",function () {
        $(".modal").css("display","");
        $(".modal").removeClass("in");
        $(".modal-backdrop").removeClass("in");
    });
});